package com.qumitech.visualnovel.component.util;

import com.alibaba.fastjson.JSON;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: yilu
 * @Date: 2018/9/29 10:53
 * @Description:
 */
public class AccessThirdRest {
    public static <T> T accessPostRest(String url, String requestBody,Class<T> responseType){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> strEntity = new HttpEntity<String>(requestBody,headers);
        String resp = restTemplate.postForObject(url,strEntity, String.class);
        //JSONObject jsonObject = JSON.parseObject(resp);
        String s = "{\n" +
                "    \"ret\": 0,\n" +
                "    \"msg\": {\n" +
                "        \"token\": \"d61d34eada2d66780c36273570ed5912\",\n" +
                "        \"promoter_access\": 1,\n" +
                "        \"master_id\": 0,\n" +
                "        \"g_master_id\": 0,\n" +
                "        \"root_id\": 0,\n" +
                "        \"master_name\": \"\",\n" +
                "        \"master_invite_code\": \"\",\n" +
                "        \"has_fellows\": 0,\n" +
                "        \"grade_num\": 0,\n" +
                "        \"grade_desc\": \"预备推广员\",\n" +
                "        \"is_register\": 0,\n" +
                "        \"invite_rule\": \"http://dwc.kiifun.com/dwc/tuiguangyun/images/img_wyzq2.png\",\n" +
                "        \"invite_code\": \"10001\",\n" +
                "        \"invite_url\": \"http://dwc.kiifun.com/dwc/tuiguangyun/lucky_money.html?userId=1&product_id=DOUQU&sign=d61d34eada2d66780c36273570ed5912&downloadLink=http://home.huanlefish.com/download/douqu/douqu1.html\",\n" +
                "        \"is_promote_newer\": 1,\n" +
                "        \"register_time\": \"2018-09-29 11:59:34\"\n" +
                "    }\n" +
                "}";

        Class<T> response= JSON.parseObject(s,responseType.getClass());;//jsonObject.toJavaObject(responseType.getClass());
        return (T) response;
    }


}
